import java.sql.*;

public class JdbcTest {
    public static void main(String[] args) {
        //1.导入数据库驱动jar包
        //2.注册数据库驱动程序
       try {
           // DriverManager.registerDriver(new Driver());
           // 推荐  实现解耦   Driver 全限定类名
          Class.forName("com.mysql.cj.jdbc.Driver");
       } catch (ClassNotFoundException e) {
           throw new RuntimeException(e);
       }
        String rul = "jdbc:mysql://localhost:3306/company";
       try(//3.建立和数据库的连接
           Connection conn = DriverManager.getConnection(rul, "root", "");
           Statement stat = conn.createStatement();
       ) {
           //4.编写Sql语句
           String sql = "insert into dept value (50,'张三','西安');";
           //5. 执行sql  有返回值
           String string ="INSERT INTO dept values (68,'李四','北京')";
//           stat.executeUpdate(string);
           int i = stat.executeUpdate(sql);
           //6. 解析返回值
           if (i > 0) {
               System.out.println("成功");
           } else {
               System.out.println("失败");
           }
       } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }
}
